<?php
class IndexAction extends CommonAction {
	
	public $Menu;
	
	public function __construct(){
		parent::__construct();
		$this->Menu = D('Menu');
		
	}
	
    public function index(){
    	$this->display();
    }

    // 2th and 3rd level 
    public function menu(){
    	
    	if(isset($_REQUEST['mid'])){
    		$mid = $_REQUEST['mid'];
    	}else{
    		$mid = C('DEFAULT_MENU');
    	}
    	
   		$myMenu = $_SESSION['menus'];
    	$menus = array(); 
   		$sub   = array();
   		
    	foreach($myMenu as $m){ 
    		if($m['level']==2 && $m['pid']==$mid){ // 二级菜单
    			$menus[] = $m;
    		}
    		if($m['level']==3){ //三级菜单 
    			$sub[] = $m;
    		}
    	}

    	foreach($menus as $k=>$m){ //构造一个数组方便模板输出
    		foreach ($sub as $s){
    			if($s['pid']==$m['id']){
    				$menus[$k]['sub'][] = $s;
    			}
    		}
    	}
// 		dump($myMenu);
    	$this->assign('menus',$menus);
    	$this->display();
    	
    }
    
    //top menu
    public function top(){
    	
    	$myMenu = $_SESSION['menus'];
    	foreach($myMenu as $m){
    		if($m['level']==1){
    			$menus[] = $m;
    		}
    	}
    	$this->assign('menus',$menus);
    	$this->display();
    	
    }
    
    public function foot(){
    	$this->display();
    }
    
    public function drag(){
    	$this->display();
    }
    
       
    
}